﻿#region Imports
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualBasic;
#endregion

namespace IntelliSearch.Utilities
{
    public static class AlphaNumerics
    {
        private static Dictionary<string, List<char>> buttons;
        public static Dictionary<string, List<char>> AlphaNumValues
        {
            get
            {
                buttons = new Dictionary<string, List<char>>();
                "!?@,ABC,DEF,GHI,JKL,MNO,PQRS,TUV,WXYZ, ".ToUpper().Split(',').ToList()
                    .ForEach(grp => buttons.Add(Strings.Right((buttons.Count() + 1).ToString(), 1), grp.ToCharArray().ToList()));

                return buttons;
            }
        }

        public static bool CheckAlphaNumAssoc(string source, int pos, char num)
        {
            if (source.Length < pos || !Information.IsNumeric(num) || !AlphaNumValues.ContainsKey(num.ToString())) return false;

            char toValidate = source.ToUpper().ElementAt(pos - 1);
            return AlphaNumValues[num.ToString()].Contains(toValidate);
        }
    }
}
